package com.yueqian.dao;

import com.yueqian.domain.Member;
import com.yueqian.domain.Orders;
import com.yueqian.domain.Product;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface IOrdersDao {
    @Select("select * from orders")
    //还要根据查订单表出来的产品id查询产品表的名称和金额
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "orderNum", property = "orderNum"),
            @Result(column = "orderTime", property = "orderTime"),
            @Result(column = "orderStatus", property = "orderStatus"),
            @Result(column = "productId", property = "product", javaType = Product.class,
                    one = @One(select = "com.yueqian.dao.IProductDao.findById", fetchType = FetchType.LAZY))
    })
    List<Orders> findAll() throws Exception;


    @Select("select * from orders where id=#{oid}")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "orderNum", property = "orderNum"),
            @Result(column = "orderTime", property = "orderTime"),
            @Result(column = "orderStatus", property = "orderStatus"),
            @Result(column = "peopleCount", property = "peopleCount"),
            @Result(column = "payType", property = "payType"),
            @Result(column = "orderDesc", property = "orderDesc"),
            @Result(column = "productId", property = "product", javaType = Product.class,
                    one = @One(select = "com.yueqian.dao.IProductDao.findById", fetchType = FetchType.LAZY)),
            @Result(column = "memberId", property = "member", javaType = Member.class,
                    one = @One(select = "com.yueqian.dao.IMemberDao.findById", fetchType = FetchType.LAZY)),
            @Result(column = "id", property = "travellers", javaType = List.class,
                    many = @Many(select = "com.yueqian.dao.ITravellersDao.findTravellersById", fetchType = FetchType.LAZY))
    })
    Orders findById(String oid) throws Exception;
}
